package org.tx.paypal.client;


import com.paypal.http.HttpResponse;
import com.paypal.http.serializer.Json;
import com.paypal.payments.Capture;
import com.paypal.payments.CapturesGetRequest;
import com.paypal.payments.LinkDescription;
import org.json.JSONObject;

import java.io.IOException;

public class CapturesGet extends PayPalClient {

	private String clientId = "ARhzyOahSH227z0VIxqfjtkJ4ShCxv3HtbskgttUZJRngsmfrvs3SKh_hWk-9wFi2N1fy8sy0-n527u9";
	private String clientSecret = "EN2TdvNlmT5F5dH9ZfeB8EuPX-UGJ1-rwh4lgyI8HShws6sRoBDWTJIjL7XZCnvi9WaM12YFhdQCpLul";
	private String mode = "sandbox";

	public static void main(String[] args) {
		try {
			new CapturesGet().testCapturesGetRequest();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public void testCapturesGetRequest() throws IOException {//扣款id， CaptureOrder生成
		CapturesGetRequest request = new CapturesGetRequest("P2020052514440001");

		HttpResponse<Capture> response = client(mode, clientId, clientSecret).execute(request);
		System.out.println("Status Code: " + response.statusCode());
		System.out.println("Status: " + response.result().status());
		System.out.println("Capture ids: " + response.result().id());
		System.out.println("Links: ");
		for (LinkDescription link : response.result().links()) {
			System.out.println("\t" + link.rel() + ": " + link.href() + "\tCall Type: " + link.method());
		}
		System.out.println("Full response body:");
		System.out.println(new JSONObject(new Json().serialize(response.result())).toString(4));
	}
}

